﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.bs;
using Domain.Entity.sys;
using Domain.Entity.zct;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Application.CustomerService
{
    public class CustomerService : ICustomerService
    {
        private readonly ICustomerRepository customerRepository;
        private readonly IMapper mapper;

        public CustomerService(ICustomerRepository customerRepository, IMapper mapper)
        {
            this.customerRepository = customerRepository;
            this.mapper = mapper;
        }

        public Task<int> AddCustomer(AddCustomerDto addcustomerDto)
        {
            Customer customer = mapper.Map<Customer>(addcustomerDto);
            return customerRepository.AddCustomer(customer);
        }

        public Task<int> DeleteCustomer(int id)
        {
            return customerRepository.DeleteCustomer(id);
        }

        public Task<int> UpdateCustomer(UpdateCustomerDto updatecustomerDto)
        {
            Customer customer = mapper.Map<Customer>(updatecustomerDto);
            return customerRepository.UpdateCustomer(customer);
        }

        public Task<FenYe<Customer>> GetCustomer(FenYe<Customer> fenYe, string? cust_code, string? cust_name, int? cust_status, string? cust_industry, string? cust_userName)
        {
            return customerRepository.GetCustomer(fenYe,cust_code, cust_name, cust_status, cust_industry, cust_userName);
        }

        public Task<List<Department>> GetDepartment(int? Department_id)
        {
            return customerRepository.GetDepartment(Department_id);
        }

        public Task<List<User>> GetUser(int? Department_id)
        {
            return customerRepository.GetUser(Department_id);
        }

        public Task<List<DictData>> GetDictData(int dict_id)
        {
            return customerRepository.GetDictData(dict_id);
        }

        public Task<Customer> GetIdCustomer(int id)
        {
            return customerRepository.GetIdCustomer(id);
        }

        public Task<FenYe<Customer>> GetSeniorCustomer(FenYe<Customer> fenYe, string? cust_code, string? cust_name, string? cust_industry, string? cust_type, string? cust_linkman, string? cust_linkphone, string? cust_email, string? cust_depName, string? cust_userName, int? cust_status, string? cust_address, string? cust_accountName, string? cust_taxpayerNum, string? cust_bankAccount, string? cust_openBank, string? create_name, string? startTime, string? endTime)
        {
                return customerRepository.GetSeniorCustomer(fenYe, cust_code, cust_name, cust_industry, cust_type, cust_linkman, cust_linkphone, cust_email, cust_depName, cust_userName, cust_status, cust_address, cust_accountName, cust_taxpayerNum, cust_bankAccount, cust_openBank, create_name, startTime, endTime);
        }

        /// <summary>
        /// 查询所有供应商编号
        /// </summary>
        public Task<List<string>> GetCustomerID()
        {
            return customerRepository.GetCustomerID();
        }

        //切换状态
        public async Task<int> UpdateStatus(int id, int sup_status)
        {
            return await customerRepository.UpdateStatus(id, sup_status);
        }


        //查询所有客户
        public async Task<List<Customer>> GetCustomers()
        {
            return await customerRepository.GetCustomers();
        }
    }
}
